package com.itheima.health.consumer;

import com.itheima.health.common.RedisConst;
import com.itheima.health.common.RocketMqConst;
import com.itheima.health.pojo.MsgTask;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Slf4j
@Component
@RocketMQMessageListener(topic = RocketMqConst.TOPIC_SMS_SEND,consumerGroup = "sms-send1")
public class SmsSendConsumer implements RocketMQListener<MsgTask>{

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void onMessage(MsgTask msgTask) {

        //log.info("[验证码] :",msgTask.getContent());
        //redisTemplate.opsForValue().set(RedisConst.VALIDATE_CODE_PRE + msgTask.getType() + "_"
        //        + msgTask.getPhone(),msgTask.getContent()+"",30L, TimeUnit.SECONDS);

        log.info("[短信发送消费者]received message: {}",msgTask.getContent());
        log.info("[短信发送消费者]模拟发送，发送中……");
        log.info("[短信发送消费者]发送成功");

        //redisTemplate.opsForValue().set(RedisConst.VALIDATE_CODE_PRE + msgTask.getType() + "_"
        //       + msgTask.getPhone(),msgTask.getContent()+"",30L, TimeUnit.SECONDS);

        redisTemplate.boundValueOps(RedisConst.VALIDATE_CODE_PRE + msgTask.getType() + "_"
                + msgTask.getPhone()).set(msgTask.getContent()+"", 100L, TimeUnit.SECONDS);

    }
}
